package com.ruoyi.test_tree.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.test_tree.domain.DeviceType;
import com.ruoyi.test_tree.service.IDeviceTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 测试设备类型树表Controller
 * 
 * @author ruoyi
 * @date 2025-07-30
 */
@RestController
@RequestMapping("/test/testTree")
public class DeviceTypeController extends BaseController
{
    @Autowired
    private IDeviceTypeService deviceTypeService;

    /**
     * 查询测试设备类型树表列表
     */
    @PreAuthorize("@ss.hasPermi('test:testTree:list')")
    @GetMapping("/list")
    public AjaxResult list(DeviceType deviceType)
    {
        List<DeviceType> list = deviceTypeService.selectDeviceTypeList(deviceType);
        return success(list);
    }

    /**
     * 导出测试设备类型树表列表
     */
    @PreAuthorize("@ss.hasPermi('test:testTree:export')")
    @Log(title = "测试设备类型树表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceType deviceType)
    {
        List<DeviceType> list = deviceTypeService.selectDeviceTypeList(deviceType);
        ExcelUtil<DeviceType> util = new ExcelUtil<DeviceType>(DeviceType.class);
        util.exportExcel(response, list, "测试设备类型树表数据");
    }

    /**
     * 获取测试设备类型树表详细信息
     */
    @PreAuthorize("@ss.hasPermi('test:testTree:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(deviceTypeService.selectDeviceTypeByTypeId(typeId));
    }

    /**
     * 新增测试设备类型树表
     */
    @PreAuthorize("@ss.hasPermi('test:testTree:add')")
    @Log(title = "测试设备类型树表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceType deviceType)
    {
        return toAjax(deviceTypeService.insertDeviceType(deviceType));
    }

    /**
     * 修改测试设备类型树表
     */
    @PreAuthorize("@ss.hasPermi('test:testTree:edit')")
    @Log(title = "测试设备类型树表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceType deviceType)
    {
        return toAjax(deviceTypeService.updateDeviceType(deviceType));
    }

    /**
     * 删除测试设备类型树表
     */
    @PreAuthorize("@ss.hasPermi('test:testTree:remove')")
    @Log(title = "测试设备类型树表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(deviceTypeService.deleteDeviceTypeByTypeIds(typeIds));
    }
}
